/** Xac dinh ham lang nghe mot su kien nao do. */
function registerListener(eventName, objID, embedID, handler){
    var obj = document.getElementById(objID);
    if(!obj){
        obj = document.getElementById(embedID);
    }
    
    if(obj){
        if(document.addEventListener){   // ho tro dom event level-2
            obj.addEventListener(eventName,handler,false);
        }else{
            obj.attachEvent('on'+eventName, handler);
        }
    }
}


function showProgress(){
    var percentLoaded = parseInt((document.video.GetMaxTimeLoaded()/document.video.GetDuration())*100); 
    document.getElementById('status').innerHTML="Percent Loaded: %";
}

function videoLoaded(){
    document.getElementById('status').innerHTML = "Video Loaded";
}
function videoEnded(){
    document.getElementById('status').innerHTML = "Video Ended";
    document.video.SetURL('love.mp3');
}


function register(){
    registerListener('qt_progress','video','video_embed', showProgress);
    registerListener('qt_load','video','video_embed', videoLoaded);
    registerListener('qt_ended', 'video','video_embed', videoEnded);
}

